<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="http://web.hcoriental.com/site.css">
    <script src="https://cdn.jsdelivr.net/npm/clipboard@1/dist/clipboard.min.js"></script>
    <script src="http://activity.hcoriental.com/jquery-3.3.1.min.js"></script>
</head>

<body style="padding-top: 4rem">
<div id="page1">
    <div class="header">
        <a href="xingyuncp://open/charge?chooseIndex=0">
            <input type="button" class="goToRecharge">
        </a>
        <h1>线下自助充值</h1>
    </div>
    <div class="content">
        <div class="box">
            <h2>第一步</h2>
            <p>通过线下各种方式转帐 , 充入您的金额 , 官方收款信息：</p>
            <div class="card">
                <p class="bankinfo my-0">{{bankcard.bank}}</p>
                <p class="bankinfo mb-0 mt-1 d-inline-block" id="bankCard">{{bankcard.account_number}}</p>
                <a id="copy" class="copybtn d-inline-block message" href="javascript:void(0)"
                   data-clipboard-target="#bankCard">一键复制</a>
                <p class="bankinfo my-0 d-inline-block" id="bankOwner" style="margin-top: 0.5rem;">{{bankcard.account_holder}}</p>
                <a id="copyOwner" class="copybtn d-inline-block message" href="javascript:void(0)"
                   data-clipboard-target="#bankOwner">一键复制</a>
            </div>
            <div class="py-1 mt-1">
                <img class="icon-warn valign-center" src="http://p.hcoriental.com/ico-warn.png">
                <span class="message d-inline-block valign-center left" style="width: 83%">银行卡信息可能会变更，在您转账前请确保为最新银行卡信息，或转账前联系客服获取最新信息。</span>
            </div>
        </div>
        <div class="box">
            <h2>第二步</h2>
            <p>转帐成功后 , 提交您的充值申请</p>
            <a href="?P=2" class="btn mx-auto">提交申请</a>
        </div>

        <div class="box">
            <h2>第三步</h2>
            <p>工作人员会在5分钟以内处理您的申请,系统将发消息提醒您充值到帐,如有疑问请联系24小时
                <a href="xingyuncp://open/kefu"><span class="goToKefu"> "在线客服" </span></a>咨询</p>
        </div>
    </div>
</div>
<div id="page2">
    <div class="header">
        <input type="button" onclick="history.back()">
        <h1>提交自助充值申请</h1>
    </div>
    <div class="content">
        <div class="list mt-2">
            <h4>我的ID</h4>
            <p class="idname">{{user_id}}</p>
        </div>
        <div class="list">
            <h4>转帐方式</h4>
            <select id="bankStyle" value='bankcard'>
                <option value="bankcard">银行卡转账</option>
                <option value="alipay">支付宝</option>
                <option value="wechat">微信</option>
                <option value="others">其他方式转账</option>
            </select>
        </div>
        <div class="list" id="applyBank">
            <h4>充值银行</h4>
            <select id="bank">
                <option value="1">请选择您的开户银行</option>
                <option value="工商银行">工商银行</option>
                <option value="建设银行">建设银行</option>
                <option value="中国银行">中国银行</option>
                <option value="农业银行">农业银行</option>
                <option value="交通银行">交通银行</option>
                <option value="招商银行">招商银行</option>
                <option value="中信银行">中信银行</option>
                <option value="光大银行">光大银行</option>
                <option value="华夏银行">华夏银行</option>
                <option value="浦发银行">浦发银行</option>
                <option value="兴业银行">兴业银行</option>
                <option value="民生银行">民生银行</option>
                <option value="平安银行">平安银行</option>
                <option value="广发银行">广发银行</option>
                <option value="其它银行">其它银行</option>
            </select>
        </div>
        <div class="list">
            <h4>到帐金额</h4>
            <input id="amount"  type="number" class="put" maxlength="12" placeholder="请输入实际到帐金额"/>
        </div>
        <div class="list" id="listNotShow" style="display: none">
            <h4 id="listId">银行卡号</h4>
            <input id="bankId" type="text" class="put" maxlength="24" placeholder="请输入您转账的银行卡卡号">
        </div>
        <div class="list">
            <h4 id="listName">银行卡姓名</h4>
            <input id="bankName" type="text" class="put" maxlength="20" placeholder="请输入您转账的银行卡户名">
        </div>

        <a class="btn mx-auto mt-2" id="checkSubmit">确认提交</a>

        <div class="info mt-2 px-1">
            <h4>充值说明：</h4>
            1. 充值前请先确保官方收款信息无误 .
            <br/> 2. 请确保您提交的充值信息无误 .
            <br/> 3. 申请提交后客服会尽快处理 .
            <br/> 4. 若有充值问题 , 请联系24小时
            <a href="xingyuncp://open/kefu"><span class="goToKefu"> "在线客服" </span></a>进行处理.
        </div>
    </div>
</div>
<div id="page3">
    <div class="header">
        <a href="xingyuncp://open/charge?chooseIndex=0">
            <input type="button" class="goToRecharge">
        </a>
        <h1>提交自助充值申请</h1>
    </div>
    <div class="content">
        <div class="box center mt-2">
            <img class="succeed" src="http://p.hcoriental.com/succeed.png" alt="自助充值成功">
            <h3>自助充值申请提交成功！</h3>
            <p>客服人员会在5分钟以内处理，
                <br/> 请留意站内消息通知。
            </p>
        </div>
        <a id="backToHome" class="btn mt-3 mx-auto" href="xingyuncp://open/home?index=0">返 回</a>
    </div>
</div>
</body>
<script>
    window.onload = function () {
        // 擷取url參數值
        function GetRequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }

        //回首页
        $('#backToHome').click(function () {
            if (window.cp && window.cp.excuteCommand) {
                window.cp.excuteCommand("xingyuncp://open/home?index=0");
            } else if (window.G && window.G.wkwebview) {
                window.webkit.messageHandlers.cp.postMessage({"name": "executeCommand", "command": 'xingyuncp://open/home?index=0'});

            } else {
                console.log("not support cp");
            }
        })

        //连结至客服ds
        $('.goToKefu').click(function () {
            if (window.cp && window.cp.excuteCommand) {
                window.cp.excuteCommand("xingyuncp://open/kefu");
            } else if (window.G && window.G.wkwebview) {
                window.webkit.messageHandlers.cp.postMessage({"name": "executeCommand", "command": 'xingyuncp://open/kefu'});

            } else {
                console.log("not support cp");
            }
        })


        var request = new Object(); //擷取url參數類別
        var page = 0; //頁面變數
        var textObj = {
            listId: '银行卡号',
            listName: '银行卡姓名',
            bankId: '请输入您转账的银行卡卡号',
            bankName: '请输入您转账的银行卡户名',
            vbankId: '请输入正确的银行卡号',
            vbankName: '请输入正确的真实姓名'
        }//顯示訊息變數
        request = GetRequest();
        page = request["P"]
        // 頁面切換
        switch (page) {
            case "2":
                $("#page1").hide();
                $("#page2").show();
                $("#page3").hide();
                break;
            case "3":
                $("#page1").hide();
                $("#page2").hide();
                $("#page3").show();
                break;

            default:
                $("#page1").show();
                $("#page2").hide();
                $("#page3").hide();
                break;
        }

        //一鍵複製觸發方法
        $("#copy").click(
            function oneTouchCopy() {
                var clipboard = new Clipboard('.copybtn', {
                    container: document.getElementById('bankCard')
                });
                clipboard.on('success', function (e) {
                    console.log('複製成功');
                    e.clearSelection();
                });

                clipboard.on('error', function (e) {
                    console.log('複製失敗')
                    console.error('Action:', e.action);
                    console.error('Trigger:', e.trigger);
                });
            });

        $("#copyOwner").click(
            function oneTouchCopy() {
                var clipboardOwner = new Clipboard('.copybtn', {
                    container: document.getElementById('bankOwner')
                });
                clipboardOwner.on('success', function (e) {
                    console.log('複製成功')
                    e.clearSelection();
                });

                clipboardOwner.on('error', function (e) {
                    console.log('複製失敗')
                    console.error('Action:', e.action);
                    console.error('Trigger:', e.trigger);
                });
            });


        // 轉換帳戶資訊
        $("#bankStyle").change(function () {
            var transfer = $("#bankStyle").val();
            var listNotShow = document.querySelector("#listNotShow")
            var listId = document.querySelector('#listId');
            var listName = document.querySelector('#listName');
            var bankId = document.querySelector('#bankId');
            var bankName = document.querySelector('#bankName');
            $('#bankId').val('')
            switch (transfer) {
                case "bankcard":
                    $("#listNotShow").hide();
                    $("#applyBank").show();
                    textObj = {
                        listId: '银行卡号',
                        listName: '银行卡姓名',
                        bankId: '请输入您转账的银行卡卡号',
                        bankName: '请输入您转账的银行卡户名',
                        vbankId: '请输入正确的银行卡号',
                        vbankName: '请输入正确的真实姓名'
                    }
                    break;
                case "alipay":$("#listNotShow").show();

                    $("#applyBank").hide();
                    textObj = {
                        listId: '支付宝账号',
                        listName: '支付宝姓名',
                        bankId: '请输入您转账的支付宝账号',
                        bankName: '请输入您转账的支付宝姓名',
                        vbankId: '请输入正确的支付宝账号',
                        vbankName: '请输入正确的真实姓名'
                    }
                    break;
                case "wechat":
                    $("#listNotShow").show();
                    $("#applyBank").hide();
                    textObj = {
                        listId: '微信账号',
                        listName: '微信姓名',
                        bankId: '请输入您转账的微信账号',
                        bankName: '请输入您转账的微信姓名',
                        vbankId: '请输入正确的微信账号',
                        vbankName: '请输入正确的真实姓名'
                    }
                    break;
                case "others":
                    $("#listNotShow").hide();
                    $("#applyBank").hide();
                    textObj = {
                        listId: '转账账号',
                        listName: '真实姓名',
                        bankId: '请输入您的账号信息',
                        bankName: '请输入您的账号绑定的真实姓名',
                        vbankId: '请输入正确的转账账号',
                        vbankName: '请输入正确的真实姓名'
                    }
                    break;
            }
            listId.textContent = textObj.listId;
            listName.textContent = textObj.listName;
            bankId.setAttribute("placeholder", textObj.bankId);
            bankName.setAttribute("placeholder", textObj.bankName);
        });

        // 確認提交按鈕事件
        $("#checkSubmit").click(function () {
            // 表單驗證
            var bankStyle = $("#bankStyle").val().trim()
            var bank = $("#bank").val().trim()
            var verificationMsg = ""
            var amount = $("#amount").val().trim()
            var bankId = $("#bankId").val().trim()
            var bankName = $("#bankName").val().trim()
            // 表單驗證
            if (bankStyle === 'bankcard') {
                if (bank == null || bank == undefined || bank == 1) {
                    verificationMsg += "请选择您的开户银行" + "\n"
                    alert(verificationMsg)
                    return
                }
                // if ((bankId.length < 14 || bankId.length > 23) && bankId != "") {
                //     verificationMsg += "请输入正确的银行卡号" + "\n"
                //     alert(verificationMsg)
                //     return
                // }
            }
            if (amount <= 0) {
                alert("请输入正确到账金额\n")
                return

            }
            if ((bankId == null || bankId == undefined || bankId == "") && (bankStyle != 'bankcard')){
                alert(textObj.vbankId + "\n")
                return
            }
            if (bankName == null || bankName == undefined || bankName == "") {
                alert(textObj.vbankName)
                return
            }
            if (verificationMsg != "") {
                //表單驗證錯誤訊息顯示
                alert(verificationMsg)
            }
            if (bankStyle !== 'bankcard') {
                bank = '';
            }

            $.ajax({
                url: '{{charge_fill_url}}',
                type: 'post',
                data: {
                    pay_type: bankStyle,
                    amount: amount,
                    pay_account_bank: bank,
                    pay_account_num: bankId,
                    pay_account_username: bankName,
                    random_num: '{{random_num}}',
                    out_trade_no: '{{out_trade_no}}',
                    order_id: '{{order_id}}',
                    sign: '{{sign}}'
                },
                error: function (xhr) {
                    alert('请求发送失败')
                },
                success: function (response) {
                    alert('请求发送成功');
                    window.location.replace(location.origin + location.pathname + "?P=3");
                }
            });
        });

    }

</script>
</html>

